﻿

--入职设定修改
CREATE proc [dbo].[proc_Employee_EntrySetEdit]
(
	@eid int,
	@departmentid nvarchar(4),
	@PCompanyId int,
	@postid int,
	@postcategory int,
	@gradeid int,
	@pluralist nvarchar(50),
	@rtx nvarchar(20),
	@wageCardNo nvarchar(50),
	@RuzhiDate nvarchar(50),
	@ProbationFrom datetime,
	@ProbationTo datetime,
	@ZzDate nvarchar(50),
	@LizhiDate nvarchar(50),
	@Proposer nvarchar(50),
	@State int,
	@ZhiWu nvarchar(50),
	@IsTxlz bit,
	@IsInsured INT,
	@Pid int,
	@Cid int,
	@id INT,
	@XZJB NVARCHAR(20)
	
)
as
	--修改employee_Entry表
	--update employee_Entry set TDepartmentId=@departmentid,TPCompanyId=@PCompanyId,TPostid=@postid,TGradeid=@gradeid,TPluralist=@pluralist,TRtx=@rtx,TWageCardNo=@wageCardNo,TRuzhiDate=@RuzhiDate,TPostcategory=@postcategory,TProbationFrom=@ProbationFrom,TProbationTo=@ProbationTo,Proposer=@Proposer,ApplionTime=getdate(),TZhiWu=@ZhiWu where eid=@eid
	declare @estate int
	set @estate = (select state from employee  where id=@eid)
		
	--当前状态为3(试用)的时候，对当前记录更新
	if(@estate = 3)
		begin
		--修改employee表 
		update employee 
		set
		    departmentId=@departmentid,
	        postid=@postid,
		    gradeid=@gradeid,
		    pluralist=@pluralist,
		    rtx=@rtx,
		    wageNumber=(SELECT TOP(1) TWageNumber from Employee_Entry where Eid=@id),
		    wageCardNo=@wageCardNo,
		    RuzhiDate=@RuzhiDate,
		    postcategory=@postcategory,
		    ProbationFrom =@ProbationFrom,
		    ProbationTo =@ProbationTo,
		    UpTime = getdate(),
		    ZhiWu = @ZhiWu,
		    IsTxlz = @IsTxlz,
		    IsInsured=@IsInsured,
			Pid = @Pid,
			Cid = @Cid,
			XZJB = @XZJB
		    --LizhiDate = @LizhiDate,
		    --State=@State
		where id = @eid
		end
	--只有当前状态为4(正式)的时候，对当前记录更新
	if(@estate = 4)
		begin
		update employee 
		set
		    departmentId=@departmentid,
	                 postid=@postid,
		    gradeid=@gradeid,
		    pluralist=@pluralist,
		    rtx=@rtx,
		    wageNumber=(SELECT TOP(1) TWageNumber from Employee_Entry where Eid=@id),
		    wageCardNo=@wageCardNo,
		    RuzhiDate=@RuzhiDate,
		    postcategory=@postcategory,
		    ProbationFrom =@ProbationFrom,
		    ProbationTo =@ProbationTo,
		    UpTime = getdate(),
		    ZzDate = @ZzDate,
		    ZhiWu=@ZhiWu,
		    IsTxlz = @IsTxlz,
		    IsInsured=@IsInsured,
			Pid = @Pid,
			Cid = @Cid,
			XZJB = @XZJB
		    --State=@State
		where id = @eid
		end
	--只有当前状态为5(离职)的时候，对当前记录更新
	if(@estate = 5)
		begin
		update employee 
		set
		    departmentId=@departmentid,
	        postid=@postid,
		    gradeid=@gradeid,
		    pluralist=@pluralist,
		    rtx=@rtx,
		    wageNumber=(SELECT TOP(1) TWageNumber from Employee_Entry where Eid=@id),
		    wageCardNo=@wageCardNo,
		    RuzhiDate=@RuzhiDate,
		    postcategory=@postcategory,
		    ProbationFrom =@ProbationFrom,
		    ProbationTo =@ProbationTo,
		    UpTime = getdate(),
		    ZzDate = @ZzDate,
		    LizhiDate = @LizhiDate,
		    ZhiWu=@ZhiWu,
		    IsTxlz = @IsTxlz,
		    IsInsured=@IsInsured,
			Pid = @Pid,
			Cid = @Cid,
			XZJB = @XZJB
		where id = @eid
		end

